package com.easychat;

import com.easychat.entity.config.WebSocketConfig;
import com.easychat.entity.constants.RedisConstants;
import com.easychat.redis.RedisCache;
import com.easychat.utils.SensitiveWordUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

/**
 * @Author Dongdong
 * @注释
 */

@SpringBootApplication(scanBasePackages = "com.easychat")
@MapperScan(basePackages = "com.easychat.mappers")
@EnableTransactionManagement//事务
@EnableScheduling//任务调度
@EnableAsync//异步
public class EasyChatApplication {
    @Resource
    private RedisCache redisCache;
    @Resource
    private WebSocketConfig webSocketConfig;

    private static final Logger logger = LoggerFactory.getLogger(EasyChatApplication.class);


    public static void main(String[] args) {
        SpringApplication.run(EasyChatApplication.class,args);
    }

    @PostConstruct
    public void test(){
//        List<WebSocketConfig.PortConfig> ports = webSocketConfig.getPorts();
//        Set<Integer> webSocketPort = redisCache.getZSetAllElements(RedisConstants.REDIS_KEY_WS_PORTS);
//        for(WebSocketConfig.PortConfig port : ports){
//            int p = port.getPort();
//            if (webSocketPort.contains(p)){
//                continue;
//            }
//            redisCache.add(RedisConstants.REDIS_KEY_WS_PORTS,p,0);
//            logger.info("WebSocketPort:{}，加载成功",p);
//        }

        //todo  去数据库查敏感词
        List<String> words = Arrays.asList("敏感词1", "敏感词2", "测试敏感词");
        SensitiveWordUtils.loadWord(words);;
    }
}
